local k = KEYS[1]
local salesKey = KEYS[2]
local n = ARGV[1] 
local stock = redis.call("DECRBY", k, n)
local res = {0, stock}

if stock < 0 then
  stock = redis.call("INCRBY", k, n)
  res[1] = -1 
  res[2] = stock
else
  redis.call("INCRBY", salesKey, n)
end

return res